<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="symbolId" :fill="color" />
  </svg>
</template>

<script>
import { defineComponent, computed } from 'vue'

export default defineComponent({
  name: 'SvgIcon',
  props: {
    name: {
      type: String,
      required: true
    },
    prefix: {
      type: String,
      default: 'icon'
    },
    color: {
      type: String,
      default: ''
    }
  },
  setup (props) {
    const symbolId = computed(() => `#${props.prefix}-${props.name}`)
    const svgClass = computed(() => props.className ? `dc-svg-icon ${props.className}` : 'dc-svg-icon');
    return { symbolId, svgClass }
  }
})
</script>

<style scoped>
.dc-svg-icon {
  /* 继承父级颜色 */
  fill: currentColor;
  vertical-align: middle;
}
</style>